/**
 * test case for api_accounts
 */
describe("api_accounts", function() {
	beforeEach(function() {
		App.initSession();
	});
	
	describe('bsoi productList', function() {
		var callback = jasmine.createSpy();
		beforeEach(function() {
			spyOn(bsoi, "productList").andCallFake(function() {
				t_productListResponse = {
					"responseHeader": {
						"status": 1,
						"currentTimestamp": "2013-01-31T14:32:41.261+0800",
						"nonce": "e1656939cfb5dcee6ea6ab063f116ada"
					},
					"productListResponse": {
						"cardList": [{
							"outStandingBalance": 0,
							"availableCreditLimit": 26000,
							"paymentDate": "2012-04-22T00:00:00.000+0800",
							"paymentDueDate": "2012-05-14T00:00:00.000+0800",
							"pastDueFlag": "N",
							"productCode": "CCA",
							"subProductCode": "100",
							"accountNumber": "5149161000903899",
							"accountDescription": "MASTERCARD PLATINUM REWARDS",
							"currencyCode": "SGD",
							"currentBalance": 0,
							"availableBalance": 26000,
							"onlineFlag": false,
							"accountNumberDisplay": "MASTERCARD PLATINUM REWARDS"
						},
						{
							"outStandingBalance": -87.85,
							"availableCreditLimit": 26000,
							"paymentDate": "2012-12-28T00:00:00.000+0800",
							"paymentDueDate": "2013-01-20T00:00:00.000+0800",
							"pastDueFlag": "N",
							"productCode": "CCA",
							"subProductCode": "123",
							"accountNumber": "5149161230898414",
							"accountDescription": "MANHATTAN PLATINUM",
							"currencyCode": "SGD",
							"currentBalance": -87.85,
							"availableBalance": 26087.85,
							"onlineFlag": false,
							"accountNumberDisplay": "MANHATTAN PLATINUM"
						},
						{
							"outStandingBalance": 2911.01,
							"availableCreditLimit": 26000,
							"paymentDate": "2012-12-28T00:00:00.000+0800",
							"paymentDueDate": "2013-01-20T00:00:00.000+0800",
							"pastDueFlag": "Y",
							"productCode": "CCA",
							"subProductCode": "160",
							"accountNumber": "5498341600051417",
							"accountDescription": "PREFERRED WORLD MASTERCARD",
							"currencyCode": "SGD",
							"currentBalance": 2911.01,
							"availableBalance": 23088.99,
							"onlineFlag": false,
							"accountNumberDisplay": "PREFERRED WORLD MASTERCARD"
						},
						{
							"outStandingBalance": 635.43,
							"availableCreditLimit": 26000,
							"paymentDate": "2012-12-28T00:00:00.000+0800",
							"paymentDueDate": "2013-01-20T00:00:00.000+0800",
							"pastDueFlag": "Y",
							"productCode": "CCA",
							"subProductCode": "162",
							"accountNumber": "5498341620109476",
							"accountDescription": "BONUS$AVER WORLD MASTERCARD",
							"currencyCode": "SGD",
							"currentBalance": 635.43,
							"availableBalance": 25364.57,
							"onlineFlag": false,
							"accountNumberDisplay": "BONUS$AVER WORLD MASTERCARD"
						}],
						"loanList": [],
						"productList": [{
							"localCurrentBalance": 1.04,
							"localAvailableBalance": 1.04,
							"productCode": "DDA",
							"subProductCode": "331",
							"accountNumber": "2319499533",
							"accountName": "",
							"accountDescription": "XTRASAVER ACCOUNT",
							"accountStatus": "",
							"currencyCode": "SGD",
							"currentBalance": 1.04,
							"availableBalance": 1.04,
							"onlineFlag": false,
							"accountNumberDisplay": "XTRASAVER ACCOUNT"
						},
						{
							"localCurrentBalance": 6086.46,
							"localAvailableBalance": 6086.46,
							"productCode": "RSV",
							"subProductCode": "507",
							"accountNumber": "2329993069",
							"accountName": "",
							"accountDescription": "E$AVER A/C",
							"accountStatus": "",
							"currencyCode": "SGD",
							"currentBalance": 6086.46,
							"availableBalance": 6086.46,
							"onlineFlag": false,
							"accountNumberDisplay": "E$AVER A/C"
						},
						{
							"localCurrentBalance": 0.00,
							"localAvailableBalance": 0.00,
							"productCode": "DDA",
							"subProductCode": "329",
							"accountNumber": "0102592330",
							"accountName": "",
							"accountDescription": "SECURITIES SETTLEMENT ACCOUNT",
							"accountStatus": "",
							"currencyCode": "SGD",
							"currentBalance": 0.00,
							"availableBalance": 0.00,
							"onlineFlag": false,
							"accountNumberDisplay": "SECURITIES SETTLEMENT ACCOUNT"
						},
						{
							"localCurrentBalance": 0.00,
							"localAvailableBalance": 0.00,
							"productCode": "DDA",
							"subProductCode": "308",
							"accountNumber": "0108780015",
							"accountName": "",
							"accountDescription": "DASH BONUS$AVER",
							"accountStatus": "",
							"currencyCode": "SGD",
							"currentBalance": 0.00,
							"availableBalance": 0.00,
							"onlineFlag": false,
							"accountNumberDisplay": "DASH BONUS$AVER"
						},
						{
							"localCurrentBalance": 0.00,
							"localAvailableBalance": 0.00,
							"productCode": "DDA",
							"subProductCode": "308",
							"accountNumber": "0108780023",
							"accountName": "",
							"accountDescription": "DASH BONUS$AVER",
							"accountStatus": "",
							"currencyCode": "SGD",
							"currentBalance": 0.00,
							"availableBalance": 0.00,
							"onlineFlag": false,
							"accountNumberDisplay": "DASH BONUS$AVER"
						},
						{
							"localCurrentBalance": 878.00,
							"localAvailableBalance": 878.00,
							"productCode": "DDA",
							"subProductCode": "320",
							"accountNumber": "0109787439",
							"accountName": "",
							"accountDescription": "PREFERRED CURRENT ACCOUNT",
							"accountStatus": "",
							"currencyCode": "SGD",
							"currentBalance": 878.00,
							"availableBalance": 878.00,
							"onlineFlag": false,
							"accountNumberDisplay": "PREFERRED CURRENT ACCOUNT"
						},
						{
							"localCurrentBalance": 0.00,
							"localAvailableBalance": 0.00,
							"productCode": "DDA",
							"subProductCode": "330",
							"accountNumber": "0170643751",
							"accountName": "",
							"accountDescription": "FCY SECURITIES SETTLEMENT ACCOUNT",
							"accountStatus": "",
							"currencyCode": "USD",
							"currentBalance": 0.00,
							"availableBalance": 0.00,
							"onlineFlag": false,
							"accountNumberDisplay": "FCY SECURITIES SETTLEMENT ACCOUNT"
						},
						{
							"localCurrentBalance": 43600.04,
							"localAvailableBalance": 43600.04,
							"productCode": "DDA",
							"subProductCode": "337",
							"accountNumber": "6119467665",
							"accountName": "",
							"accountDescription": "BONUS$AVER",
							"accountStatus": "",
							"currencyCode": "SGD",
							"currentBalance": 43600.04,
							"availableBalance": 43600.04,
							"onlineFlag": false,
							"accountNumberDisplay": "BONUS$AVER"
						},
						{
							"localCurrentBalance": 0.00,
							"localAvailableBalance": 0.00,
							"productCode": "RSV",
							"subProductCode": "515",
							"accountNumber": "0129629308",
							"accountName": "",
							"accountDescription": "DASH E$AVER",
							"accountStatus": "",
							"currencyCode": "SGD",
							"currentBalance": 0.00,
							"availableBalance": 0.00,
							"onlineFlag": false,
							"accountNumberDisplay": "DASH E$AVER"
						},
						{
							"localCurrentBalance": 0.00,
							"localAvailableBalance": 0.00,
							"productCode": "RSV",
							"subProductCode": "515",
							"accountNumber": "0129629316",
							"accountName": "",
							"accountDescription": "DASH E$AVER",
							"accountStatus": "",
							"currencyCode": "SGD",
							"currentBalance": 0.00,
							"availableBalance": 0.00,
							"onlineFlag": false,
							"accountNumberDisplay": "DASH E$AVER"
						},
						{
							"localCurrentBalance": 0.0000,
							"localAvailableBalance": 0.0000,
							"repaymentAlternateCurrency": 0,
							"productCode": "SXA",
							"subProductCode": "",
							"accountNumber": "067476801",
							"accountDescription": "SECURITIES TRADING ACCOUNT",
							"currencyCode": "SGD",
							"currentBalance": 0.0000,
							"availableBalance": 0.0000,
							"onlineFlag": false,
							"accountNumberDisplay": "SECURITIES TRADING ACCOUNT"
						}]
					}
				};
				App.api_accounts._processProductList(t_productListResponse);
				// return t_productListResponse;
			});
		});

		it('User can see ProductList', function() {
			spyOn(App.api_accounts, "_processProductList");
			
			App.api_accounts.productList(callback);
			
			expect(App.api_accounts.callbackProductList).toEqual(callback);
			expect(bsoi.productList).toHaveBeenCalled();
			
			expect(App.api_accounts._processProductList).toHaveBeenCalledWith(t_productListResponse);
		});

		it('User can get Account by account number', function(){
			var _account = App.api_accounts.getAccountByNumber('5498341620109476');
			expect(_account).toEqual(null);

			spyOn(bsoi, "validateResponse");
			App.api_accounts._processProductList(t_productListResponse);
			_account = App.api_accounts.getAccountByNumber('5498341620109476');

			expect(_account.get('name')).toEqual('BONUS$AVER WORLD MASTERCARD');
		});
	});
});